#include "defines.h"

class cElement
{
	public cElement(int id)
	{
		intProps = new int[PROPS.IIDX_COUNT];		
		strProps = new String[PROPS.SIDX_COUNT];
		bounds = new short[PROPS.BOUND_COUNT];
		
		for(int i = 0; i < PROPS.BOUND_COUNT; i++)
		{
			bounds[i] = PROPS.DEFAULT_BOUND;
		}
		
		int intTypedParams = 0;
		int strTypedParams = 0;
		
		for(int i = 0; i < PROPS.FPARAMS_TYPES[id].length; i++)
		{
			if(
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_INT ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_HEX_STRING ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_APP_COMBO ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_SCR_COMBO ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_ALL_COMBO ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_ACTBIND_COMBO ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_FRM_BUTTON_FLAGS
				)
			{
				intTypedParams++;
			}
			else if(
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_STRING ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_MNUTYPE_COMBO ||
				PROPS.FPARAMS_TYPES[id][i] == PROPS.FTYPE_TXTYPE_COMBO
				)
			{
				strTypedParams++;
			}
		}
		
		intFlagsParams = new int[intTypedParams];
		strFlagsParams = new String[strTypedParams];
	}
	
	public int[] intProps;
	public String[] strProps;
	
	public int[] actions;
	public int[] intActionsParams;
	public String[] strActionsParams;
	
	public int[] intFlagsParams;
	public String[] strFlagsParams;
	
	public int state;
	public int selIndex = 0; // only for menu
	public int childs = 0; // only for menu
	
	// img: used by ELEM_TYPES.IMG and ELEM_TYPES.MNU (as the image for the selector)
	javax.microedition.lcdui.Image img = null; // TODO: replace by a sprite... or not?
	
	public short[] bounds;
	
	private int flagsBackUp = 0;
	
	// btnTextOffX, scrollLeft: used by ELEM_TYPES.BTN because of flag FLG_SCROLL_HORIZONTALLY
	private int btnTextOffX = 0;
	private boolean scrollLeft = true;	
	
	private boolean swapColors = false;
	
	public void backUpFlags()
	{
		flagsBackUp = intProps[PROPS.IIDX_FLG];
	}
	
	public void restoreFlags()
	{
		intProps[PROPS.IIDX_FLG] = flagsBackUp;
	}
	
	public boolean isFlagEnabled(int flagId)
	{
		int myId = intProps[PROPS.IIDX_ID] >> 24;
		for(int i = 0; i < PROPS.FLAGS[myId].length; i++)
		{
			if(flagId == PROPS.FLAGS[myId][i])
			{
				return ((intProps[PROPS.IIDX_FLG] & (1 << i)) != 0);
			}
		}
		return false;
	}
	
	public void setFlag(int flagId, boolean value)
	{
		int myId = intProps[PROPS.IIDX_ID] >> 24;
		for(int i = 0; i < PROPS.FLAGS[myId].length; i++)
		{
			if(flagId == PROPS.FLAGS[myId][i])
			{
				if(value)
				{
					intProps[PROPS.IIDX_FLG] |= (1 << i);
					break;
				}
				else
				{
					intProps[PROPS.IIDX_FLG] &=~ (1 << i);
					break;
				}
			}
		}
	}
	
	public void Draw(DGraph g, boolean isSelected)
	{
		Draw(g, isSelected, null);
	}
	
	public void Draw(DGraph g, boolean isSelected, cElement menuFather)
	{
		switch(intProps[PROPS.IIDX_ID] >> 24)
		{
			case ELEM_TYPES.MNU:
			break;
			
			case ELEM_TYPES.BTN:
				DrawButton(g, isSelected, menuFather);
			break;
			
			case ELEM_TYPES.TXT:
				if (strProps[PROPS.SIDX_TTP].equalsIgnoreCase("DP")) 
				{
					DrawDisplayTextBox(g);
				}
				else if (strProps[PROPS.SIDX_TTP].equalsIgnoreCase("IP")) 
				{
					DrawInputTextBox(g);
				}
				else
				{
					cGame.error = "Unknown Text Box Type";
				}
			break;
			
			case ELEM_TYPES.IMG:
				DrawImage(g, isSelected);
			break;

			case ELEM_TYPES.SCV:	//EMY SCROLLVIEW
				break;
			
			default:
		}
	}
	
	public void DrawImage(DGraph g, boolean selected)
	{
		if(strProps[PROPS.SIDX_SRC].equals(""))
		{
			return;
		}
	
		if(isFlagEnabled(PROPS.FLG_ORIGINAL_SIZE))
		{
			if(img == null)
			{
				img = g.loadImage(strProps[PROPS.SIDX_SRC]);
			}
			
			g.drawImage(img, intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], 0);
		}
		else if(isFlagEnabled(PROPS.FLG_STRETCH_OR_MOSAIC)) // stretch
		{
			if(img == null)
			{
				img = DGraph.stretchImageFromFile(strProps[PROPS.SIDX_SRC], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH]);
			}
			
			g.drawImage(img, intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], 0);
		}
		else if(!isFlagEnabled(PROPS.FLG_STRETCH_OR_MOSAIC)) // mosaic
		{
			if(img == null)
			{
				img = g.loadImage(strProps[PROPS.SIDX_SRC]);
			}
			
			g.saveClip();
			
			g.setClip(intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH]);
			
			int imgW = img.getWidth();
			int imgH = img.getHeight();
			
			for(int curX = intProps[PROPS.IIDX_RCX]; curX < intProps[PROPS.IIDX_RCX] + intProps[PROPS.IIDX_RCW]; curX += imgW)
			{
				for(int curY = intProps[PROPS.IIDX_RCY]; curY < intProps[PROPS.IIDX_RCY] + intProps[PROPS.IIDX_RCH]; curY += imgH)
				{
					g.drawImage(img, curX, curY, 0);
				}
			}
			
			g.restoreClip();
		}
		
		if(selected)
		{
			g.setColor(0xFFFF00);
			g.drawRect(intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW] - 1, intProps[PROPS.IIDX_RCH] - 1);
		}
	}
	
	public void DrawMenu(DGraph g, boolean isSelected)
	{
		if(state == ELEM_STATES.MNU_CLOSED)
		{
			g.drawVistaButton(strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], intProps[PROPS.IIDX_BGC], intProps[PROPS.IIDX_FGC], isSelected);
		}		
		else if(state == ELEM_STATES.MNU_OPENED)
		{
			if(isFlagEnabled(PROPS.FLG_SELECTOR_IMAGE) && img == null)
			{
				img = DGraph.resizeImage(g.loadImage(strFlagsParams[0]), cGame.proportional);
				
				int i = 0;
				for(i = 0; i < cGame.paintList[ELEM_TYPES.MNU].length; i++)
				{
					if(cGame.elements[ELEM_TYPES.MNU][cGame.paintList[ELEM_TYPES.MNU][i]] == this)
					{
						break;
					}
				}
				
				for(int j = 0; j < cGame.menusList[i].length; j++)
				{
					cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].intProps[PROPS.IIDX_RCW] += (img.getWidth() * 2);
					
					if(cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].intProps[PROPS.IIDX_RCX] + cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].intProps[PROPS.IIDX_RCW] > SCREEN_WIDTH)
					{
						cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].intProps[PROPS.IIDX_RCX] = SCREEN_WIDTH - cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].intProps[PROPS.IIDX_RCW];
					}
				}
			}
			
			g.drawVistaButton(strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], intProps[PROPS.IIDX_FGC], intProps[PROPS.IIDX_FGC], intProps[PROPS.IIDX_FTC], intProps[PROPS.IIDX_AFC], true);
			
			int i = 0;
			for(i = 0; i < cGame.paintList[ELEM_TYPES.MNU].length; i++)
			{
				if(cGame.elements[ELEM_TYPES.MNU][cGame.paintList[ELEM_TYPES.MNU][i]] == this)
				{
					break;
				}
			}
			
			for(int j = 0; j < cGame.menusList[i].length; j++)
			{
				if(cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].isFlagEnabled(PROPS.FLG_ENABLED)
				|| cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].isFlagEnabled(PROPS.FLG_VISIBLE_DISABLED))
				{
					if(IS_EVEN(j))
					{
						swapColors = true;
					}
					else
					{
						swapColors = false;
					}
					
					cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].Draw(g, selIndex == j, this);
					if(selIndex == j)
					{
						cGame.selectedElement = cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]];
					}
				}
			}
		}
	}

	public void DrawScrollView(DGraph g) //EMY SCROLLVIEW
	{
		int i = 0;
		cElement element = null;
		for(i = 0; i < cGame.paintList[ELEM_TYPES.SCV].length; i++)	 // busco la lista que tengo q pintar.
		{
			if(cGame.elements[ELEM_TYPES.SCV][cGame.paintList[ELEM_TYPES.SCV][i]] == this)
			{
				break;
			}
		}
		
		for (int k = 0; k < cGame.scrollViewList[i].length; k++) // recorro todos los tipos de elementos que tiene la scroll view actual. 
		{ 
			for (int j = 0; j < cGame.scrollViewList[i][k].length ; j++)  // recorro todos los elementos que tiene la scroll view actual.
			{
				// Aca dependiendo de q tipo de elemento sea, llamo al metodo de pintado requerido.
				element = cGame.elements[k][cGame.scrollViewList[i][k][j]];
				switch (element.intProps[PROPS.IIDX_ID] >> 24)
				{
					case ELEM_TYPES.BTN:
					{
						element.DrawButton(g, false);
						break;
					}
					case ELEM_TYPES.IMG:
					{
						element.DrawImage(g, false);
						break;
					}
					case ELEM_TYPES.TXT:
					{
						if (element.strProps[PROPS.SIDX_TTP].equalsIgnoreCase("DP")) 
						{
							element.DrawDisplayTextBox(g);
						}
						else if (element.strProps[PROPS.SIDX_TTP].equalsIgnoreCase("IP")) 
						{
							element.DrawInputTextBox(g);					
						}
						else
						{
							cGame.error = "Unknown Text Box Type";
						}
						break;
					}
				}
			}
		}
	}
	
	public void DrawButton(DGraph g, boolean selected, cElement menuFather)
	{
		g.setFontColor(0xFFFFFF);
		
		if(isFlagEnabled(PROPS.FLG_SCROLL_HORIZONTALLY) && selected)
		{
			if(g.getStringWidth(strProps[PROPS.SIDX_NAME]) > (intProps[PROPS.IIDX_RCW] - (intProps[PROPS.IIDX_RCW] >> 4) * 3))
			{
				if(scrollLeft)
				{
					btnTextOffX--;
					
					if(intProps[PROPS.IIDX_RCX] + SCRW_PER(5) + ((intProps[PROPS.IIDX_RCW] >> 4) * 3) + btnTextOffX + g.getStringWidth(strProps[PROPS.SIDX_NAME])
					< intProps[PROPS.IIDX_RCX] + (intProps[PROPS.IIDX_RCW] - (intProps[PROPS.IIDX_RCW] >> 4) * 3))
					{
						scrollLeft = false;
					}
					
					cGame.tmplHander_repaint = true;
				}
				else
				{
					btnTextOffX++;
					if(btnTextOffX == SCRW_PER(5))
					{
						scrollLeft = true;
					}
					cGame.tmplHander_repaint = true;
				}
			}
		}
		else
		{
			btnTextOffX = 0;
		}
		
		if(menuFather == null)
		{
			g.drawVistaButton(strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], intProps[PROPS.IIDX_BGC], 0x30227, state == ELEM_STATES.BTN_PRESSED || selected);
		}
		else
		{		
			int bgColor = intProps[PROPS.IIDX_BGC];
			if(menuFather.isFlagEnabled(PROPS.FLG_INTERLAY_COLORS) && menuFather.swapColors)
			{
				if(bgColor > 0x777777)
				{
					bgColor = g.fadeColor(bgColor);
				}
				else
				{
					bgColor = g.highlightColor(bgColor);
				}
			}
		
			if(menuFather.isFlagEnabled(PROPS.FLG_SELECTOR_IMAGE))
			{
				g.drawButton((!selected)? null : menuFather.img, strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], bgColor, intProps[PROPS.IIDX_FGC], intProps[PROPS.IIDX_FTC], intProps[PROPS.IIDX_AFC], state == ELEM_STATES.BTN_PRESSED || selected, btnTextOffX);
			}
			else
			{
				g.drawButton(strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], bgColor, intProps[PROPS.IIDX_FGC], intProps[PROPS.IIDX_FTC], intProps[PROPS.IIDX_AFC], state == ELEM_STATES.BTN_PRESSED || selected, btnTextOffX);
			}
		}
	}
	
	public void DrawButton(DGraph g, boolean selected)
	{
		DrawButton(g, selected, null);
	}
	
	public void DrawInputTextBox(DGraph g)
	{
		g.drawInputTextBox(intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], intProps[PROPS.IIDX_BGC], intProps[PROPS.IIDX_FTC], true, false);
	}
	
	public void DrawDisplayTextBox(DGraph g)
	{
		g.drawDisplayTextBox(strProps[PROPS.SIDX_NAME], intProps[PROPS.IIDX_RCX], intProps[PROPS.IIDX_RCY], intProps[PROPS.IIDX_RCW], intProps[PROPS.IIDX_RCH], 10, 3, intProps[PROPS.IIDX_BGC], intProps[PROPS.IIDX_FTC]);
	}
	
	public boolean update(int action)
	{
		switch(intProps[PROPS.IIDX_ID] >> 24)
		{
			case ELEM_TYPES.MNU:
				
				if(action == ACTIONS.SELECT && cGame.selectedMenu == null && this == cGame.selectedElement)
				{
					if(isFlagEnabled(PROPS.FLG_ACTION_DIRECTLY))
					{
						int i = 0;
						for(i = 0; i < cGame.paintList[ELEM_TYPES.MNU].length; i++)
						{
							if(cGame.elements[ELEM_TYPES.MNU][cGame.paintList[ELEM_TYPES.MNU][i]] == this)
							{
								break;
							}
						}
						
						cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][0]].update(action);
					}
					else
					{
						state = ELEM_STATES.MNU_OPENED;
						cGame.paintingMenu = true;
						cGame.tmplHander_repaint = true;
						cGame.selectedMenu = this;
					}
					return true;
				}
				else if(action == ACTIONS.SELECT && cGame.selectedMenu == this)
				{
					int i = 0;
					for(i = 0; i < cGame.paintList[ELEM_TYPES.MNU].length; i++)
					{
						if(cGame.elements[ELEM_TYPES.MNU][cGame.paintList[ELEM_TYPES.MNU][i]] == this)
						{
							break;
						}
					}
					
					for(int j = 0; j < cGame.menusList[i].length; j++)
					{
						if(cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].isFlagEnabled(PROPS.FLG_ENABLED))
						{
							if(cGame.elements[ELEM_TYPES.BTN][cGame.menusList[i][j]].update(action))
							{
								return true;
							}
						}
					}
				}
				else if(action == ACTIONS.BACK && cGame.selectedMenu != null)
				{
					state = ELEM_STATES.MNU_CLOSED;
					cGame.paintingMenu = false;
					cGame.tmplHander_repaint = true;
					cGame.selectedMenu = null;
					cGame.selectedElement = this;
					selIndex = 0;
					return true;
				}
				
			break;
			
			case ELEM_TYPES.BTN:
			
				if(intProps[PROPS.IIDX_ACT] == action && action != ACTIONS.NONE)
				{
					state = ELEM_STATES.BTN_PRESSED;
					cGame.tmplHander_repaint = true;
					return true;
				}
				else if(action == ACTIONS.NONE && state != ELEM_STATES.BTN_IDLE)
				{
					state = ELEM_STATES.BTN_IDLE;
					cGame.tmplHander_repaint = true;
				}
				else if(action == ACTIONS.SELECT && cGame.selectedElement == this)
				{
					cGame.performActions(actions, intActionsParams, strActionsParams);
					return true;
				}
				
			return false;
			
			case ELEM_TYPES.TXT:
				if (strProps[PROPS.SIDX_TTP].equalsIgnoreCase("DP"))
				{
				}
				else if (strProps[PROPS.SIDX_TTP].equalsIgnoreCase("IP"))
				{
					//TODO: sacar de la tool
//					updateInputTextBox(string, maxChars, isAlphaNum);					
				}
				else
				{
					cGame.error = "Unknown Text Box Type";
				}
			break;
			
			case ELEM_TYPES.IMG:
			
				if(action == ACTIONS.SELECT && cGame.selectedElement == this)
				{
					cGame.performActions(actions, intActionsParams, strActionsParams);
					return true;
				}
				
			break;
			
			default:
		}
		
		return false;
	}	
	
	public static long lastInput 	= 0;
	public static int lastPress 	= 48;
	public static int pressOff 		= 0;
	
	//TODO: implementar flag en el templateHandler para decir si es un input numerico o alfanumerico.
	
	public String updateInputTextBox(String str, int maxChars, boolean isAlphaNum)
	{
		if(System.currentTimeMillis() - lastInput > KEYS.INPUT_THRESHOLD && str.length() < maxChars)
		{
			for(int i = KEYS.KEY_0; i <= KEYS.KEY_9; i++)
			{
				if(cGame.isKeyPressed(i))
				{
					if(i == lastPress && System.currentTimeMillis() - lastInput < 2000 && str.length() > 0)
					{
						str = str.substring(0, str.length() - 1);
						pressOff++;
					}
					else
					{
						pressOff = 0;
					}
					
					if(isAlphaNum)
					{
						if(pressOff >= KEYS.CHARS[i - KEYS.KEY_0].length)
							pressOff -= KEYS.CHARS[i - KEYS.KEY_0].length;
						
						str = str + KEYS.CHARS[i - KEYS.KEY_0][pressOff];
					}
					else
					{
						if(pressOff >= KEYS.NUM_CHARS[i - KEYS.KEY_0].length)
							pressOff -= KEYS.NUM_CHARS[i - KEYS.KEY_0].length;
						
						str = str + KEYS.NUM_CHARS[i - KEYS.KEY_0][pressOff];
					}
					
					lastPress = i;
					lastInput = System.currentTimeMillis();
				}
			}
		}
		
		if(System.currentTimeMillis() - lastInput > KEYS.INPUT_THRESHOLD)
		{
			if(cGame.isKeyPressed(KEYS.SET[KEYS.IDX_LEFT]) && str.length() > 0)
			{
				lastInput = System.currentTimeMillis();
				pressOff = 0;
				str = str.substring(0, str.length() - 1);
			}
		}
		
		return str;
	}
}

interface ELEM_STATES
{
	public static final int MNU_CLOSED		= 0;
	public static final int MNU_OPENED		= MNU_CLOSED + 1;
	
	public static final int BTN_IDLE		= 0;
	public static final int BTN_PRESSED		= BTN_IDLE + 1;
	public static final int BTN_RELEASED	= BTN_PRESSED + 1;
}

interface ELEM_TYPES
{
	public static final int APP 	= 0;
	public static final int SCR 	= APP + 1;
	public static final int MNU 	= SCR + 1;
	public static final int SCV 	= MNU + 1; //EMY SCROLLVIEW
	public static final int BTN 	= SCV + 1;
	public static final int TXT 	= BTN + 1;
	public static final int IMG 	= TXT + 1;
	public static final int COUNT 	= IMG + 1;
}

interface PROPS
{
	public static final int IIDX_ID 		= 0;
	public static final int IIDX_EP			= IIDX_ID + 1;
	public static final int IIDX_BGC		= IIDX_EP + 1;
	public static final int IIDX_FGC		= IIDX_BGC + 1;
	public static final int IIDX_FTC		= IIDX_FGC + 1;
	public static final int IIDX_AFC		= IIDX_FTC + 1;
	public static final int IIDX_FTR		= IIDX_AFC + 1;
	public static final int IIDX_RCX		= IIDX_FTR + 1;
	public static final int IIDX_RCY		= IIDX_RCX + 1;
	public static final int IIDX_RCW		= IIDX_RCY + 1;
	public static final int IIDX_RCH		= IIDX_RCW + 1;
	public static final int IIDX_ACT		= IIDX_RCH + 1;
	public static final int IIDX_FLG		= IIDX_ACT + 1;
	public static final int IIDX_COUNT		= IIDX_FLG + 1;
		
	public static final int SIDX_DUMMY		= -1;
	public static final int SIDX_NAME		= 0;
	public static final int SIDX_MTP		= SIDX_NAME + 1;
	public static final int SIDX_TTP		= SIDX_MTP + 1;
	public static final int SIDX_SRC		= SIDX_TTP + 1;
	public static final int SIDX_COUNT		= SIDX_SRC + 1;
	
	public static final int MNUTYPE_TB		= 0;
	public static final int MNUTYPE_SC		= MNUTYPE_TB + 1;
	public static final int MNUTYPE_SK		= MNUTYPE_SC + 1;
	
	public static final int TXTTYPE_DP		= 0;
	public static final int TXTTYPE_IP		= TXTTYPE_DP + 1;
	
	
	public static final int[][] IINDEXES = {
											{IIDX_ID, IIDX_EP, IIDX_BGC, IIDX_FGC, IIDX_FTC, IIDX_AFC, IIDX_ACT}, // APP
											{IIDX_ID, IIDX_BGC, IIDX_FGC, IIDX_FTC, IIDX_AFC, IIDX_ACT, IIDX_FTR, IIDX_FLG}, // SCR
											{IIDX_ID, IIDX_BGC, IIDX_FGC, IIDX_FTC, IIDX_AFC, IIDX_ACT, IIDX_FTR, IIDX_FLG}, // MNU
											{IIDX_ID, IIDX_RCX, IIDX_RCY, IIDX_RCW, IIDX_RCH, IIDX_BGC, IIDX_FGC, IIDX_FTC, IIDX_AFC, IIDX_FTR, IIDX_FLG}, // SCV
											{IIDX_ID, IIDX_RCX, IIDX_RCY, IIDX_RCW, IIDX_RCH, IIDX_BGC, IIDX_FGC, IIDX_FTC, IIDX_AFC, IIDX_ACT, IIDX_FTR, IIDX_FLG}, // BTN
											{IIDX_ID, IIDX_RCX, IIDX_RCY, IIDX_RCW, IIDX_RCH, IIDX_BGC, IIDX_FTC, IIDX_AFC, IIDX_ACT, IIDX_FTR, IIDX_FLG}, // TXT
											{IIDX_ID, IIDX_RCX, IIDX_RCY, IIDX_RCW, IIDX_RCH, IIDX_FTR, IIDX_FLG} // IMG
										};
										
	public static final int FLG_TAB_INDEX 			= 0;
	public static final int FLG_IN_ALL_SCREENS 		= FLG_TAB_INDEX + 1;
	public static final int FLG_ENABLED 			= FLG_IN_ALL_SCREENS + 1;
	public static final int FLG_VISIBLE_DISABLED	= FLG_ENABLED + 1;
	public static final int FLG_ACTION_DIRECTLY		= FLG_VISIBLE_DISABLED + 1;
	public static final int FLG_REPAINT_BACKGROUND	= FLG_ACTION_DIRECTLY + 1;
	public static final int FLG_IS_BACKGROUND_IMAGE	= FLG_REPAINT_BACKGROUND + 1;
	public static final int FLG_ORIGINAL_SIZE		= FLG_IS_BACKGROUND_IMAGE + 1;
	public static final int FLG_STRETCH_OR_MOSAIC	= FLG_ORIGINAL_SIZE + 1;
	public static final int FLG_PLAIN_PNG			= FLG_STRETCH_OR_MOSAIC + 1;
	public static final int FLG_SELECTOR_IMAGE		= FLG_PLAIN_PNG + 1;
	public static final int FLG_INTERLAY_COLORS		= FLG_SELECTOR_IMAGE + 1;
	public static final int FLG_SCROLL_HORIZONTALLY	= FLG_INTERLAY_COLORS + 1;
	public static final int FLG_USE_BIG_FONT		= FLG_SCROLL_HORIZONTALLY + 1;
	public static final int FLG_ROUND_BOXES			= FLG_USE_BIG_FONT + 1;
										
	public static final int[][] FLAGS = {
											{}, // APP
											{FLG_REPAINT_BACKGROUND}, // SCR
											{FLG_TAB_INDEX, FLG_IN_ALL_SCREENS, FLG_ENABLED, FLG_VISIBLE_DISABLED, FLG_ACTION_DIRECTLY, FLG_SELECTOR_IMAGE, FLG_INTERLAY_COLORS}, // MNU
											{FLG_TAB_INDEX, FLG_ENABLED, FLG_VISIBLE_DISABLED}, // SCV
											{FLG_TAB_INDEX, FLG_ENABLED, FLG_VISIBLE_DISABLED, FLG_SCROLL_HORIZONTALLY, FLG_ROUND_BOXES}, // BTN
											{FLG_TAB_INDEX, FLG_ENABLED, FLG_VISIBLE_DISABLED, FLG_USE_BIG_FONT, FLG_ROUND_BOXES}, // TXT
											{FLG_TAB_INDEX, FLG_ENABLED, FLG_VISIBLE_DISABLED, FLG_IS_BACKGROUND_IMAGE, FLG_ORIGINAL_SIZE, FLG_STRETCH_OR_MOSAIC, FLG_PLAIN_PNG, FLG_IN_ALL_SCREENS} // IMG
										};
										
	public static final int[] SINDEXES_LEN = {
												1,
												0,
												2,
												0,
												1,
												2,
												1
											};
										
	public static final int[][] SINDEXES = {
											{SIDX_NAME}, // APP
											{}, // SCR
											{SIDX_NAME, SIDX_MTP}, // MNU
											{}, // SCV
											{SIDX_NAME}, // BTN
											{SIDX_NAME, SIDX_TTP}, // TXT
											{SIDX_SRC} // IMG
										};
										
	public static final int BOUND_UP 	= 0;
	public static final int BOUND_DOWN 	= BOUND_UP + 1;
	public static final int BOUND_LEFT 	= BOUND_DOWN + 1;
	public static final int BOUND_RIGHT	= BOUND_LEFT + 1;
	public static final int BOUND_COUNT	= BOUND_RIGHT + 1;
	
	public static final short DEFAULT_BOUND = (short)0xFFFF;
	public static final int INHERIT_COLOR = 0x01000000;
	
	public static final byte FTYPE_INT 						= 0;
    public static final byte FTYPE_STRING					= FTYPE_INT + 1;
    public static final byte FTYPE_HEX_STRING				= FTYPE_STRING + 1;
    public static final byte FTYPE_APP_COMBO				= FTYPE_HEX_STRING + 1;
    public static final byte FTYPE_SCR_COMBO				= FTYPE_APP_COMBO + 1;
    public static final byte FTYPE_SCR_MNU_COMBO			= FTYPE_SCR_COMBO + 1;
    public static final byte FTYPE_MNUTYPE_COMBO			= FTYPE_SCR_MNU_COMBO + 1;
    public static final byte FTYPE_TXTYPE_COMBO				= FTYPE_MNUTYPE_COMBO + 1;
    public static final byte FTYPE_ACTBIND_COMBO			= FTYPE_TXTYPE_COMBO + 1;
    public static final byte FTYPE_FRM_BUTTON_FLAGS			= FTYPE_ACTBIND_COMBO + 1;
    public static final byte FTYPE_FRM_BUTTON_ACTIONS		= FTYPE_FRM_BUTTON_FLAGS + 1;
    public static final byte FTYPE_FLAG_PARAMS				= FTYPE_FRM_BUTTON_ACTIONS + 1;
	public static final byte FTYPE_ACTIONS_PARAMS			= FTYPE_FLAG_PARAMS + 1;
	public static final byte FTYPE_PLATFORM_REQ_COMBO		= FTYPE_ACTIONS_PARAMS + 1;
    public static final byte FTYPE_ALL_COMBO				= FTYPE_PLATFORM_REQ_COMBO + 1;
    public static final byte FTYPE_PROPS_COMBO				= FTYPE_ALL_COMBO + 1;
	
	public static final byte[][] FPARAMS_TYPES = {
													{}, // APP
													{}, // SCR
													{ FTYPE_STRING }, // MNU
													{}, // SCV
													{}, // BTN
													{}, // TXT
													{} // IMG
												};
}